package com.itheima.mapper;

import com.itheima.pojo.Emp;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 员工管理
 */
@Mapper
public interface EmpMapper {

   /*
    * 原始分页查询方法 比较繁琐
   @Select("select count(*) from emp")
    public Long count();

    @Select("select * from emp limit #{page}, #{pageSize}")
    public List<Emp> getEmps(Integer page, Integer pageSize);
    */

    // 使用mybatis-pageHelper分页查询方法
    @Select("select * from emp")
    public List<Emp> getEmps();

    public void deleteEmps(List<Integer> ids);

    @Insert("insert into emp (username, name, gender, image, job, entrydate, dept_id, create_time, update_time) values " +
            "(#{username}, #{name}, #{gender}, #{image}, #{job}, #{entrydate}, #{deptId}, #{createTime}, #{updateTime})")
    void addEmp(Emp emp);

    @Select("select * from emp where id = #{id}")
    Emp searchEmp(Integer id);

    void updateEmp(Emp emp);

    /**
     * 根据用户名和密码查询员工
     * @param emp
     * @return
     */
    @Select("select * from emp where username = #{username} and password = #{password}")
    Emp login(Emp emp);

    @Delete("delete from emp where dept_id = #{deptId}")
    void deleteEmpByDeptId(Integer deptId);
}
